<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
	<title><spring:message code="message.lable.ShangPinMuLuGuanLi"/></title>
	<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
    .box-body{
    margin-top:-2px;
    }    	
    </style>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>配送方案</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#">交易</a></li>
            <li class="active"><a href="#">药品列表</a></li>
            <li class="active"><a href="#">配送方案</a></li>
        </ol>
    </section>
    
    <section class="content">
      <form id="form" method="post" class="form-horizontal">    
        <div class=" box box-success">
            <div class="box-body">
               <div class="input">
                    <div class="textalign">配送企业名称<spring:message code="message.yanZheng.maoHao"/></div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="compName" name="compName" placeholder="配送企业名称" />
                    </div>
                    <div class="textalign">
                       <button type="button" onclick="gridSerch()" class="btn btn-success btn-sm" id="selectDicCompType"><spring:message code="message.button.seachSpacing"/></button>
					</div>
               </div>
            </div>
           </div>
        </form> 
        <table class="jqgrid" id="gridlist"></table>
        <div id="prowed2"></div>
		<div class=" box box-warning bottongroup" id="bottongroup">
		    <label onclick="addDel()" class="btn btn-primary btn-sm">新 增</label>
		    <label onclick="batchDelete()" class="btn btn-primary btn-sm">删 除</label>
			<label onclick="back();" class="btn btn-primary btn-sm">返 回</label>
		</div>              
                      
            
	
<div style="margin-top: 10px;"></div>
	<form action="${ctx}/stdCompinfo/toStdCompinfoDetailJsp.html"
		id="FormDetail" method="post">
		<input type="hidden" name="compCodeDetail" id="compCodeDetail" /> 
	</form>
</section>
<%@ include file="/WEB-INF/component/commonJS.jsp"%>
<script type="text/javascript">

function back(){
	window.location.href="${ctx}/baseGoods/toList.html";
}

function addDel(){
    $.HN.dialog.opendialog('delId','选择配送企业','${ctx}/baseGoods/toGoodsSelectComp.html?goodsCode=${param.goodsCode}&areaId=${param.areaId}&delId=delId&delTxt=delTxt','800px','400px',operResult);
    }
  function operResult(val){
	  
  }


    var searchType = 0;
    
    function moreSerch(obj) {
    	if (searchType == 0) {
    		searchType = 1;
    		$("div.moreSerch").slideDown();
    		$(obj).html("<spring:message code="message.button.JianDanChaXun"/>");
    	} else {
    		searchType = 0;
    		$("div.moreSerch").slideUp();
    		$(obj).html("<spring:message code="message.button.GaoJiChaXun"/>");
    		$("#goodsCode,#drugCode,#catCompName,#isLowprice,#isSmallprice,#isSmallsource").val("");
    	}
    }

	
		

		function batchDelete() {
			var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
            	top.$.HN.message.alert("请选择要删除的配送企业！", "<spring:message code="message.HN.alert.type"/>", "warn");
                return;
            }
      	    $.HN.message.confirm('确定删除配送企业？', '', '').on(function (e) {
                if (e) {
                	var list = [];
                    for (var i=0; i<rowIds.length; i++) {
                        rowId = rowIds[i];
                        var rowdata = $("#gridlist").jqGrid('getRowData', rowId);
                        list.push({"delRelId":rowId,"compCode":rowdata.del_comp_code});
        			}
                    $.post("${ctx}/baseGoods/batchDeleteHaveSetDel.html", {
        				"array" : json.jsonToString(list),"goodsCode":"${param.goodsCode}"
        			}, function(result) {
        				if (result.success) {
        					$.HN.message.alert(result.msg, "消息", "success");
        					$("#gridlist").trigger("reloadGrid");
        				} else {
        					$.HN.message.alert(result.msg, "消息", "error");
        				}
        			}, "json");
                }
            });
    	}
	
		$(function () {
		jQuery("#gridlist").jqGrid({
			url: "${ctx}/baseGoods/getHaveSetDel.html?goodsCode=${param.goodsCode}",
		    mtype: "POST",
			datatype: "json",
			autowidth: true,
			//shrinkToFit:false,
		   	colNames:[
		   	          'del_rel_id',
		   	          '',
		   	          '配送企业名称',
		   	          '配送企业简称'
		   	          ],
		   	colModel:[
				{name:'del_rel_id',index:'del_rel_id',sortable: false,key:true,  width:100, align:"center",sorttype:false,hidden:true},
				{name:'del_comp_code',index:'del_comp_code',sortable: false,  width:100, align:"center",sorttype:false,hidden:true},
	            {name:'del_comp_name',index:'del_comp_name',sortable: false,  width:160, align:"center",sorttype:false},
		   		{name:'del_comp_name_short',sortable: false,index:'del_comp_name_short', width:100,align:"center", sorttype:false}
		   	],
			 rowNum: 20,
		     rowList: [10, 20, 50, 100],
		     rownumbers: true,
		     multiselect: true,
		     pager: "#prowed2",
		     viewrecords: true,
		     gridComplete: function(){
             	//序号列宽度自适应（参数为jqgridID）
                autoRNWidth("gridlist");
             	//数据只有一条时默认选中（参数为jqgridID）
                 selectByOneData("gridlist");
		     },
		     caption: "配送企业列表",
		     jsonReader: {
		         repeatitems: false,
		         id: "ids"
		     }
		   	
		});
			 
			jQuery("#gridlist").jqGrid('navGrid',"prowed2",{edit:false,add:false,del:false});
			$("#gridlist").jqGrid("setGridHeight",create());
			$(window).trigger("resize");
			
		});
		
		function gridSerch() {
            var compName = $.trim($("#compName").val());
            $("#gridlist").jqGrid('setGridParam', {  
                datatype:'json',
                postData:{
                    "compName":compName,
                    "goodsCode":'${param.goodsCode}'
                },
                page:1
            }).trigger("reloadGrid"); //重新载入  
        }
		
		    
		    function stop(){
		    	var checked = false;
		    	 $("input.cbox").each(function() {
		    	     if($(this).is(":checked")) {
		    	    	 checked = true;
		    	    	 return false;
		    	     };
		    	 });
		    	 
		    	 if (!checked) {
		    		 $.HN.message.alert('<spring:message code="message.yanZheng.QingXuanZeYaoStopDeTiaoMu"/>', '<spring:message code="message.HN.alert.type"/>', 'warn');
		    	 }else{
		   	 $.HN.message.confirm("<spring:message code="message.yanZheng.QueDingYaoTingYongMa"/><spring:message code="message.yanZheng.wenHao"/>", '', '').on(function (e) {
		           if (e) {
		               $.HN.message.alert('操作成功！', '<spring:message code="message.HN.alert.type"/>', 'success');
		               window.location.href="onSellDrugListCenter.jsp";
		               
		           }
		       });
			   
		       }
		    }
		   $("#allDelete1").click(function(){
			   var checked = false;
		   	 $("input.cbox").each(function() {
		   	     if($(this).is(":checked")) {
		   	    	 checked = true;
		   	    	 return false;
		   	     };
		   	 });
		   	 
		   	 if (!checked) {
		   		 $.HN.message.alert('<spring:message code="message.yanZheng.QingXuanZeYaoStartDeTiaoMu"/><spring:message code="message.yanZheng.wenHao"/>', '<spring:message code="message.HN.alert.type"/>', 'warn');
		   	 }else{
		     	 $.HN.message.confirm("<spring:message code="message.yanZheng.QueDingYaoQiYongMa"/><spring:message code="message.yanZheng.wenHao"/>", '', '').on(function (e) {
		              if (e) {
		                  $.HN.message.alert('<spring:message code="message.HN.alert.success"/>', '<spring:message code="message.HN.alert.type"/>', 'success');
		                  window.location.href="onSellDrugListCenter.jsp";
		                  
		              }
		          });
		   	 }
		     });
		   
			function goJsp(n1){
				
				var opt ={
						url:"../../jsp/price/priceChangeExeDetailGrid.jsp",
						title:"newwindow",
		style:{height:400,width:890,top:200,left:270}
				};
				$.HN.dialog.open(opt);
				
		}    
		    function selectComp(){
		 	   
		 		$("#compCode").val("");
		 	    $("#compName").val("");
		 	 gridCompSerch();
		 	   $('#selectComp').modal({
		 			keyboard : true
		 		});
		 	   
		 	  
		    }
		    function gridCompSerch() {
		    	var compCode = $("#compCode").val();
		    	var compName = $("#compName").val();
		 		$("#gridlist1").jqGrid('setGridParam',{  
		 	        datatype:'json',
		 	        postData:{"compCode":compCode,
		 	        		"compName":compName}
		 	    }).trigger("reloadGrid"); //重新载入  
		 	}
		    function gridOk(){
		 	   var compId = $("#gridlist1").jqGrid('getGridParam', 'selrow');
		        if (compId == null) {
		     	   $.HN.message.alert('<spring:message code="message.yanZheng.QingZhiShaoXuanYiTiao"/><spring:message code="message.yanZheng.ganTanHao"/>', '<spring:message code="message.HN.alert.type"/>', 'warn');
		            return;
		        }
		        var rowdata = $("#gridlist1").jqGrid('getRowData', compId);
		        $("#prodPompId").val(compId);
		        $("#comp").val(rowdata.compName);
		        $("#selectComp").modal("hide");
		        
		    }
		    function cleandata(){
		 	   $("#prodPompId").val("");
		        $("#comp").val("");
		        $("#selectComp").modal("hide");
		    }
		    function operResult(val){
		        
		    }
		    function fileUp(){
		    	$('#batchImport').modal({
                    keyboard: true
                });
		    }
		    
		    
		    $('#importform').ajaxForm({ 
			    dataType: 'json', 
		    	success: function(returnData) {
		    	if(returnData.success) {
		    		$.HN.message.alert('导入成功！', '提示信息', 'success');
		    		$("#batchImport").modal("hide");
				}else{
					$.HN.message.alert('添加失败，请重新添加！', '提示信息', 'success');
		    	}
		       } 	
		   });
</script>
</body>
</html>